package io.esirong.widget;

public class Smooth {

    int s = 0;

    //    当初速度和加速度同向时 距离S=初速度V*时间t+1/2at^2
//    当初速度和加速度反向的 S=V*T-1/2at^2
    public static double culS() {
        double v = 0;
        double t = 0;
        double a = 0;
        double s = v * t + a * t * t / 2;
        return s;

    }

    public static void main(String[] args) {
        addS();
        System.out.println("00");
    }

    //位置修正-加速追
    public static double addS() {
        double v = 1;
        double t = 0.1;
        double a = 0;

        double sActual = 30;
        double sFake = 10;
        //差距
        double dS = sActual - sFake;
        // a++;
        a = 0;
        while (sActual > sFake) {

            if (sFake < (dS * 3 / 4)) {
                a++;
            } else {
                a--;
            }

            double s = v * t + a * t * t / 2;

            if (s <= 0) {
                continue;
            }
            if (sFake < (dS * 3 / 4) && a <= 0) {
                a = 0;
            }
            if (sFake > (dS * 3 / 4) && a >= 0) {
                a = 0;
            }

            sFake += s;
        }
        System.out.println("sFake=" + sFake);
        return sFake;
    }
}
